//index.js
//获取应用实例
const app = getApp()
Page({
  data: {
    swiper1:"../../image/AirPods.jpg",
    swiper2:"../../image/iPad.jpg",
    swiper3:"../../image/bicycle.jpg",
    swiper4:"../../image/phone.jpg",
    goods:[],
    openid:""
  },
  //获取用户的openid
getopenid(){
  let that=this
  wx.cloud.callFunction({
    name:"getopenid",
    success(res){
      console.log("获取openid成功",res.result.openid)
      that.setData({
        openid:res.result.openid
      })
    },
    fail(res){
      console.log("获取openid失败",res)
    }
  })
},
  //事件处理函数
  bindViewTap: function() {
    
  },
  onLoad: function () {
    this.getopenid()
  },
  onShow: function() {
    let that=this
     wx.cloud.database().collection("list").where({
       sale_num:wx.cloud.database().command.neq(0)
     }).get({
       success(res){
          console.log("请求成功",res)
          that.setData({
            goods:res.data
          })
       },
       fail(res){
          console.log("请求失败",res)
       }
     })
  },
  getUserInfo: function(e) {
    
  },
  suo: function(option){
    wx.navigateTo({
      url: '../search/search',
    })
  },
  // 跳转到商品详情
  onGoods: function(option){
    wx.navigateTo({
      url: '../goods/goods?openid='+this.data.openid,
      success: function(res){
        res.eventChannel.emit('acceptDatafromIndex',{id:option.currentTarget.id})
      }
    })
  },
  // 跳转到手机分类
  onPhone: function(option){
    wx.navigateTo({
      url: '../class/class?openid='+this.data.openid,
      success: function(res){
        res.eventChannel.emit('acceptDatafromIndex',{text:"手机"})
      }
    })
  },
  // 跳转到自行车分类
  onBicycle: function(option){
    wx.navigateTo({
      url: '../class/class?openid='+this.data.openid,
      success: function(res){
        res.eventChannel.emit('acceptDatafromIndex',{text:"骑行"})
      }
    })
  },
  // 跳转到生活用品分类
  onSupplies: function(option){
    wx.navigateTo({
     url: '../class/class?openid='+this.data.openid,
      success: function(res){
        res.eventChannel.emit('acceptDatafromIndex',{text:"生活用品"})
      }
    })
  },
  // 跳转到学习用品分类
  onStudy: function(option){
    wx.navigateTo({
      url: '../class/class?openid='+this.data.openid,
      success: function(res){
        res.eventChannel.emit('acceptDatafromIndex',{text:"学习用品"})
      }
    })
  },
  // 跳转到服饰
  onClothe: function(option){
    wx.navigateTo({
      url: '../class/class?openid='+this.data.openid,
      success: function(res){
        res.eventChannel.emit('acceptDatafromIndex',{text:"服饰"})
      }
    })
  },
  //跳转到其他
  onOther: function(option){
    wx.navigateTo({
      url: '../class/class?openid='+this.data.openid,
      success: function(res){
        res.eventChannel.emit('acceptDatafromIndex',{text:"其他"})
      }
    })
  }
})
